package com.lcm.learn.lcmcode.proxy.cglib;

import org.springframework.cglib.core.DebuggingClassWriter;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: lcm
 * @create: 2020-01-19 09:16
 **/

public class SimpleCGLibDemo2 {

    private static <T> T getProxy(Class<T> cls) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(cls);
        enhancer.setCallback(new SimpleInterceptor());
        return (T) enhancer.create();
    }

    public static void main(String[] args) throws InterruptedException {
        B proxyService = getProxy(C.class);
        proxyService.sayHello("ss");

        C c=(C)proxyService;
        c.sayHello("ss");
    }

}

abstract class A<T> {
    public abstract String sayHello(T s) ;
}

abstract class B<T> extends A<T>{

}

class C extends B<String> {
    @Override
    @Test
    public String sayHello(String a) {
        System.out.println(a);
        return a;
    }
}
